/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package frontera;

import Control.CrudEmpleado;
import Entidad.Empleado;
import Entidad.Sistema;
import javax.swing.DefaultListModel;
import javax.swing.JOptionPane;

/**
 *
 * @author felipe
 */
public class CrearEmpleado extends javax.swing.JFrame {

    
    DefaultListModel empleadosdlm = new DefaultListModel();
    
    public CrearEmpleado() {
        initComponents();
        this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    inicializar();
    }

    public void inicializar(){
            NombreEmpleadoTF.setEditable(true);
            IDEmpleadoTF.setEditable(true);
            ContrasenaEmpleadoTF.setEditable(true);
            for(Empleado e: Sistema.getEmpleado())
            {
                empleadosdlm.addElement(e);
            }
    }
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        NombreEmpleadoTF = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        IDEmpleadoTF = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        ContrasenaEmpleadoTF = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        BotonCrearEmpleado = new javax.swing.JButton();
        ListaTipo = new javax.swing.JComboBox();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText("Nombre");

        NombreEmpleadoTF.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                NombreEmpleadoTFActionPerformed(evt);
            }
        });

        jLabel2.setText("ID");

        jLabel3.setText("Contraseña");

        jLabel4.setText("Rol");

        BotonCrearEmpleado.setText("Crear Empleado");
        BotonCrearEmpleado.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BotonCrearEmpleadoActionPerformed(evt);
            }
        });

        ListaTipo.setBackground(new java.awt.Color(255, 255, 225));
        ListaTipo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Servicio al cliente", "Servicio tecnico", "Despacho", "Call center", "Vendedor" }));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(55, 55, 55)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(BotonCrearEmpleado)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2)
                            .addComponent(jLabel3)
                            .addComponent(jLabel4))
                        .addGap(67, 67, 67)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(NombreEmpleadoTF, javax.swing.GroupLayout.DEFAULT_SIZE, 232, Short.MAX_VALUE)
                            .addComponent(IDEmpleadoTF)
                            .addComponent(ContrasenaEmpleadoTF)
                            .addComponent(ListaTipo, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                .addContainerGap(205, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(36, 36, 36)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(NombreEmpleadoTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(IDEmpleadoTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(ContrasenaEmpleadoTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(ListaTipo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 100, Short.MAX_VALUE)
                .addComponent(BotonCrearEmpleado)
                .addGap(64, 64, 64))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void NombreEmpleadoTFActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_NombreEmpleadoTFActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_NombreEmpleadoTFActionPerformed

    private void BotonCrearEmpleadoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BotonCrearEmpleadoActionPerformed
        if("".equals(NombreEmpleadoTF.getText()) || "".equals(IDEmpleadoTF.getText())){
            JOptionPane.showMessageDialog(this, "Ingrese todos los datos rtequeridos");
            
        }
        else{
            if(CrudEmpleado.crearEmpleado(Double.parseDouble(IDEmpleadoTF.getText()), NombreEmpleadoTF.getText(), (String)ListaTipo.getSelectedItem(), ContrasenaEmpleadoTF.getText())){
                JOptionPane.showMessageDialog(this, "Empleado Creado");
                PanelEmpleado.dtmempleados.addRow(new Object[] { (Double.parseDouble(IDEmpleadoTF.getText())), NombreEmpleadoTF.getText(), ContrasenaEmpleadoTF.getText(),  (String)ListaTipo.getSelectedItem()} );
            
            }
            else{
                 JOptionPane.showMessageDialog(this,"Este ID de Empleado ya existe.");
            }
            }
            
        
    }//GEN-LAST:event_BotonCrearEmpleadoActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(CrearEmpleado.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(CrearEmpleado.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(CrearEmpleado.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(CrearEmpleado.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new CrearEmpleado().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton BotonCrearEmpleado;
    private javax.swing.JTextField ContrasenaEmpleadoTF;
    private javax.swing.JTextField IDEmpleadoTF;
    private javax.swing.JComboBox ListaTipo;
    private javax.swing.JTextField NombreEmpleadoTF;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    // End of variables declaration//GEN-END:variables
}
